﻿using System;
using System.Configuration;
using System.Web.Configuration;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class ConnectionStringsSectionManager : ConfigurationManagerBase
	{
		private ConnectionStringsSection section;

		public ConnectionStringsSectionManager()
		{
			this.section = (ConnectionStringsSection)base.GetConfigurationSection("connectionStrings");
		}

		public void Add(string name, string connectionString, string providerName)
		{
			this.section.ConnectionStrings.Add(new ConnectionStringSettings(name, connectionString, providerName));
			this.Save();
		}

		public void Modify(string name, string connectionString, string providerName)
		{
			ConnectionStringSettings _connectionStringSettings = this.section.ConnectionStrings[name];
			_connectionStringSettings.ConnectionString = connectionString;
			_connectionStringSettings.ProviderName = providerName;
			this.Save();
		}

		public void Remove(string name)
		{

			this.section.ConnectionStrings.Remove(name);

			this.Save();
		}

		public void Clear()
		{
			this.section.ConnectionStrings.Clear();

			this.Save();
		}

		public ConnectionStringSettings GetSettings(string key)
		{
			return this.section.ConnectionStrings[key];
		}

		public ConnectionStringSettingsCollection GetSettingsCollection()
		{
			return this.section.ConnectionStrings;
		}
	}
}
